<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .wrong{
            color: red;
            background-image: url();
        }
        .right{
            color: green;
            background-image: url();
        }
    </style>
</head>
<body>
    <script>
        // 不足6到16位会提示错误信息
        //1.获取元素
        var ipt=document.querySelector('.input');
        var message=document.querySelector(".message");
        //2.注册事件 失去焦点
        ipt.oblur=function{
            //根据表单里面值的长度 ipt.value.length
            if(ipt.value.length<6||this.value.length>16){
                message.className="message wrong";
                message.innerHTML="你输入的位置不对";
            }else{
                message.className="message right";
                message.innerHTML="你输入的正确";
            }

        }
    </script>
</body>
</html>